//
//  FiveController.swift
//  fho
//
//  Created by 郭颢源 on 2021/3/19.
//

import UIKit

class FiveController: UITableViewController {
    
    //数据对象
    private var modelObj = MyVModel()
    //tableView
    private let cellReuseIdentifier: String = "MyReuseIdentifier"
    //头部背景图片
    private var hdView: MyHeaderView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "我的"
        
        // Do any additional setup after loading the view.
        
        //创建视图
        initViews()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        //自定义navBar样式
        self.naviBarTransparent()
    }
    
    override var preferredStatusBarStyle: UIStatusBarStyle {
        
        return .lightContent
    }
    
    // MARK: - Custom Methods
    
    private func initViews() -> Void {
        
        //修改tableView样式
        self.tableView.register(UIKTableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier)
        self.tableView.sectionHeaderHeight = 0.1
        self.tableView.sectionFooterHeight = 0.1
        self.tableView.rowHeight = 54.0
        self.tableView.separatorColor = NSKVar.SEPERATOR_COLOR
        self.tableView.backgroundColor = NSKVar.VC_BACKGROUND_COLOR
        //头部背景
        hdView = MyHeaderView(frame: CGRect(x: 0.0, y: 0.0, width: NSKVar.kScreenWidth, height: 0.2 * NSKVar.kScreenHeight))
        hdView.infoTextLabel.text = "带路小妖"
        hdView.operationClosure = { [unowned self] (typeIndex: Int) -> Void in
            //            self.operateType(index)
            print("点击了头像")
            
        }
        //设置
        self.tableView.tableHeaderView = hdView
    }
    
    
}

extension FiveController{
    
    // MARK: - UITableView Delegate DataSource
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return modelObj.data[section].count
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        
        return modelObj.data.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        //数据对象
        let tempObj = modelObj.data[indexPath.section][indexPath.row]
        //自定义cell
        let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier, for: indexPath) as! UIKTableViewCell
        //属性
        cell.attributes(tempObj)
        //返回
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        //数据对象
        let tempObj = modelObj.data[indexPath.section][indexPath.row]
        print(tempObj)
        //获取类名
        guard let viewController = (tempObj.nextClass ?? "").vc() else {
            return
        }
        //标题
        viewController.title = tempObj.name
        //下一步时隐藏底部tabBar
        viewController.hidesBottomBarWhenPushed = true
        //显示
        self.navigationController?.pushViewController(viewController, animated: true)
    }
    
}
